﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CLEXA.ClientTools;
using CLEXA.DataContracts;
using CLEXA.ServiceContracts;

namespace CLEXA.AdminClient.Services
{
    internal class AdminService : IAdminService
    {
        private readonly string uri;

        public AdminService(string uri)
        {
            this.uri = uri;
        }

        public int CreateUser(string username, string password, bool isActive)
        {
            using (Proxy<IAdminService> proxy = new Proxy<IAdminService>(uri))
            {
                return proxy.Channel.CreateUser(username, password, isActive);
            }
        }

        public List<UserData> GetAllUsers()
        {
            using (Proxy<IAdminService> proxy = new Proxy<IAdminService>(uri))
            {
                return proxy.Channel.GetAllUsers();
            }
        }

        public void DeleteUser(int userId)
        {
            using (Proxy<IAdminService> proxy = new Proxy<IAdminService>(uri))
            {
                proxy.Channel.DeleteUser(userId);
            }
        }

        public void UpdateUser(UserData user)
        {
            using (Proxy<IAdminService> proxy = new Proxy<IAdminService>(uri))
            {
                proxy.Channel.UpdateUser(user);
            }
        }

        public void ChangePassword(int userId, string password)
        {
            using (Proxy<IAdminService> proxy = new Proxy<IAdminService>(uri))
            {
                proxy.Channel.ChangePassword(userId, password);
            }
        }
    }
}
